// 红绿灯的
// then return promise 链式
const traffic_light = (color,duration) => {
    return new Promise((resolve,reject) => {
        console.log('traffic_light',color);
        setTimeout(() => {
            resolve()
        },duration)
    })
}
// 任何代码都是死循环
const main = () => {
    Promise.resolve() // fullfied promise
        .then(() => traffic_light('red',3000))
        .then(() => traffic_light('green',3000))
        .then(() => traffic_light('yellow',1000))
        .then(() => {
            main()
        })
}
main()